// Copyright Epic Games, Inc. All Rights Reserved.

#include "LyraSettingAction_SafeZoneEditor.h"

#include "DataSource/GameSettingDataSource.h"
#include "Player/LyraLocalPlayer.h"
#include "Settings/LyraGameSettingRegistry.h"
#include "Widgets/Layout/SSafeZone.h"

#include UE_INLINE_GENERATED_CPP_BY_NAME(LyraSettingAction_SafeZoneEditor)

class UGameSetting;

#define LOCTEXT_NAMESPACE "LyraSettings"

/**
 * 构造函数，初始化安全区域数值设置
 */
ULyraSettingAction_SafeZoneEditor::ULyraSettingAction_SafeZoneEditor()
{
	SafeZoneValueSetting = NewObject<ULyraSettingValueScalarDynamic_SafeZoneValue>(); // 创建安全区域数值设置对象
	SafeZoneValueSetting->SetDevName(TEXT("SafeZoneValue")); // 设置开发名称
	SafeZoneValueSetting->SetDisplayName(LOCTEXT("SafeZoneValue_Name", "安全区域值")); // 设置显示名称
	SafeZoneValueSetting->SetDescriptionRichText(LOCTEXT("SafeZoneValue_Description", "安全区域面积百分比。")); // 设置描述文本
	SafeZoneValueSetting->SetDefaultValue(0.0f); // 设置默认值
	SafeZoneValueSetting->SetDynamicGetter(GET_LOCAL_SETTINGS_FUNCTION_PATH(GetSafeZone)); // 设置动态获取函数
	SafeZoneValueSetting->SetDynamicSetter(GET_LOCAL_SETTINGS_FUNCTION_PATH(SetSafeZone)); // 设置动态设置函数
	SafeZoneValueSetting->SetDisplayFormat([](double SourceValue, double NormalizedValue){ return FText::AsNumber(SourceValue); }); // 设置显示格式
	SafeZoneValueSetting->SetSettingParent(this); // 设置父级设置
}

/**
 * 获取子设置项
 */
TArray<UGameSetting*> ULyraSettingAction_SafeZoneEditor::GetChildSettings()
{
	return { SafeZoneValueSetting }; // 返回安全区域数值设置
}

/**
 * 重置为默认值
 */
void ULyraSettingValueScalarDynamic_SafeZoneValue::ResetToDefault()
{
	Super::ResetToDefault(); // 调用父类重置方法
	SSafeZone::SetGlobalSafeZoneScale(TOptional<float>(DefaultValue.Get(0.0f))); // 设置全局安全区域缩放为默认值
}

/**
 * 恢复到初始值
 */
void ULyraSettingValueScalarDynamic_SafeZoneValue::RestoreToInitial()
{
	Super::RestoreToInitial(); // 调用父类恢复方法
	SSafeZone::SetGlobalSafeZoneScale(TOptional<float>(InitialValue)); // 设置全局安全区域缩放为初始值
}

#undef LOCTEXT_NAMESPACE